package com.dongdongshop.config;

import com.alibaba.fastjson.JSON;
import com.dongdongshop.pojo.pay.TbPayLog;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.codehaus.jettison.json.JSONString;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("test")
public class TestTxMessage {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("txMessage")
    public void txMessage(TbPayLog payLog, List<String> list){
        //发送半消息
        String str = JSON.toJSONString(list);
        //消息
        Message message= MessageBuilder.withPayload(str).build();
        //发送事物
        rocketMQTemplate.sendMessageInTransaction("tx-stockCount","countAndOrder",message,payLog);
    }
}
